<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/5/30
 * Time: 15:04
 */
namespace app\admin\controller;

use app\admin\model\BalanceModel;
use app\admin\model\UserModel;
class User extends BaseController
{
    public function __construct()
    {
       parent:: __construct();
       $this->user = new UserModel();
       $this->balance = new BalanceModel();
    }
    /**
     * 首页
     *
    */
    public function index()
    {
        $list = $this->user->index();
        $page = $list->render();
        $count = count($list);
        $this->assign('list',$list);
        $this->assign('page',$page);
        $this->assign('count',$count);
        return view('user/index');
    }
    /**
     * 会员编辑
    */
    public function edit()
    {
        if(request()->isAjax())
        {
            $res = $this->user->edit();
            if($res)
            {
                return ['code'=>'1','message'=>'修改成功'];
            }else{
                return ['code'=>'0','message'=>'修改失败'];
            }
        }
        $id = input('id');
        $data = $this->user->getOneId($id);
        $this->assign('data',$data);
        return view('user/edit');
    }
    /**
     * 用户状态修改
     * $type 1正常 0禁用
    */
    public function user_status()
    {
        $type = request()->post('type');
        $id = request()->post('id');
        $res = $this->user->user_status($id,$type);
        if($res)
        {
            return ['code'=>'1','message'=>'操作成功',['data'=>$id]];
        }else{
            return ['code'=>'0','message'=>'操作失败',['data'=>$id]];
        }
    }
    /**
     * 充值币种
    */
    public function recharge()
    {
        if(request()->isAjax())
        {
            $res = $this->balance->recharge();
            if($res)
            {
                return ['code'=>'1','message'=>'充值成功'];
            }else{
                return ['code'=>'0','message'=>'充值失败'];
            }
        }
        $id = input('id');
        $this->assign('id',$id);
        return view('user/recharge');
    }
    public function del()
    {
        $res = $this->user->del();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
    public function dell()
    {
        $res = $this->user->dell();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
}